module(...,package.seeall)
local NotiMap= {}
local NotiMap_mt = {__metatable = {}, __index = NotiMap}

function new()
	local obj=setmetatable({__noticb={}},NotiMap_mt)
	return obj
end
function NotiMap:ResetCB()
	self.__noticb={}
end
local vk={}
function NotiMap:AddCB(noti,cb)
	noti=noti or vk
	local cbx=self.__noticb[noti] or {}
	self.__noticb[noti]=cbx
	cbx[cb]=cb
end
function NotiMap:DelCB(noti,cb)
	noti=noti or vk
	local cbx=self.__noticb[noti]
	if cbx then cbx[cb]=nil end
end

function NotiMap:OnNoti(ch,bd)
	local noti=ch.noti
	local cbx=self.__noticb[noti]
	if cbx then
		for k,v in pairs(cbx) do
			local r,msg=pcall(k,noti,ch,bd)
			if not r then print(msg) end
		end
	end
	cbx=self.__noticb[vk]
	if cbx then
		for k,v in pairs(cbx) do
			local r,msg=pcall(k,noti,ch,bd)
			if not r then print(msg) end
		end
	end
end
